﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace information
{
    public partial class SearchData : Form
    {
        public SearchData()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //连接数据库
            string strcon;
            strcon = "Server=192.168.0.88; Database=information;User id ='sa';pwd=123456";  //information            
            SqlConnection myon = new SqlConnection(strcon);
            myon.Open();
            MessageBox.Show("数据库连接成功", "数据库");

            //数据输入
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("ID无输入");
                textBox1.Focus();
            }
            else
            {
                int id = Convert.ToInt32(textBox1.Text);
                string mysql = "SELECT * from InformationTable where id=" + id;               //Sql查询语句
                SqlDataAdapter myada = new SqlDataAdapter(mysql, myon);   //定义OleDbDataAdapter对象实例并连接数据库表
                DataSet myds = new DataSet();      //定义DataSet对象实例  
                myada.Fill(myds);                 //填充数据集
                dataGridView1.DataSource = myds.Tables[0].DefaultView;   //连接数据表格，显示数据
                myon.Close();    //关闭OleDbConnection对象实例
                myon.Dispose();   //释放OleDbConnection对象实例所占资源空间
            }



        }
    }
}
